﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

namespace XFSale.Aux
{
    public partial class WebMasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(Server.MapPath("~/Web.sitemap"));
                bindTreeView(xml.DocumentElement, treeSite.Nodes);
                treeSite.DataBind();

                xml = null;
            }
        }

        private void bindTreeView(XmlNode document, TreeNodeCollection nodes)
        {
            foreach (XmlNode node in document.ChildNodes)
            {
                XmlAttribute attr = node.Attributes["description"];
                if (attr != null && attr.Value != null && attr.Value.ToUpper() == "hidden".ToUpper())
                {
                    continue;
                }

                TreeNode child = new TreeNode();
                attr = node.Attributes["url"];
                child.NavigateUrl = (attr == null) ? null : attr.Value;
                attr = node.Attributes["title"];
                child.Text = (attr == null) ? null : attr.Value;
                child.Selected = Server.MapPath(child.NavigateUrl) == Request.PhysicalPath;
                //Response.Write(Server.MapPath(child.NavigateUrl) + "=");
                //Response.Write(Request.PhysicalPath + "<br/>");
                nodes.Add(child);

                bindTreeView(node, child.ChildNodes);
            }
        }

        protected void smMaster_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
        {
            //ScriptManager.RegisterClientScriptBlock(upMain, GetType(), Page.Request.Path, "alert('ssssss');", true);
            smMaster.AsyncPostBackErrorMessage = e.Exception.Message;
            //Response.Write("sssssssssssss");
        }

    }
}
